<?php
$this->breadcrumbs=array(
	'Users'=>array('index'),
	'Manage',
);

$this->menu=array(
	array('label'=>'Create User', 'url'=>array('create')),
);

$script = "
\$('.grid-view .status-column a').live('click', function(){
    if (\$(this).parents('.status-column').hasClass('disabled')) {
        alert('You can not change your own status!');
        return false;
    }
        
    $.get(\$(this).attr('href'), function(){
        $('.grid-view .filters input:first').trigger('change');
    });
    return false;
});
";
Yii::app()->clientScript->registerScript(__CLASS__.'#ChangeStatus', $script, CClientScript::POS_READY);
?>

<h1>Manage Users</h1>

<?php $grid = $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'user-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
    'selectableRows'=>2,
    'selectionChanged'=>"updateSelectors",
	'columns'=>array(
        array(
            'class'=>'CCheckBoxColumn',
            'value'=>'$data->id',
            'htmlOptions'=>array('width'=>'3%'),
        ),
		'username',
		'email',
        array(
            'name'=>'status',
            'type'=>'raw',
            'value'=>'CHtml::link($data->statusText, array("status", "ids[]"=>$data->id, "value"=>$data->status ? 0 : 1), array("class"=>($data->status ? "active" : "")))',
            'filter'=>false,
            'cssClassExpression'=>'$data->id == Yii::app()->user->id ? "disabled" : ""',
            'htmlOptions'=>array(
                'class'=>'status-column'
            )
        ),
        array(
            'name'=>'created_date',
            'value'=>'Yii::app()->getDateFormatter()->formatDateTime(strtotime($data->created_date))',
            'filter'=>false,
            'htmlOptions'=>array(
                'class'=>'datetime-column'
            )
        ),
        array(
            'name'=>'last_login',
            'value'=>'Yii::app()->getDateFormatter()->formatDateTime(strtotime($data->last_login))',
            'filter'=>false,
            'htmlOptions'=>array(
                'class'=>'datetime-column'
            )
        ),
        array(
            'name'=>'id',
            'value'=>'$data->id',
            'filter'=>false,
        ),
		array(
			'class'=>'CButtonColumn',
		),
	),
)); 

if ($grid->dataProvider->ItemCount) {
    $this->menu[] = array('label' => 'Delete selected items', 'url'=>$this->createUrl('delete'), 'linkOptions' => array('onclick'=>'return multipleDelete("user-grid",this.href)'));
}
Yii::app()->clientScript->registerScriptFile(Yii::app()->core->AssetUrl.'/scripts/gridview.js', CClientScript::POS_BEGIN);
?>